#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 9;
struct array{
	int l , r , c , be , now;
}k[N];
int idx;
bool t[N];
int main(){
	freopen( "fruit.in"  , "r" , stdin );
	freopen( "fruit.out" , "w" , stdout );
	int n , tmp , p = 0 , c[2] , cnt[2] = {0};
	scanf( "%d" , &n );
	memset( t , 1 , sizeof ( t ) );
	for ( int i = 1 ; i <= n ; i ++ ){
		scanf ( "%d" , &c[p] ) , p ^= 1 , cnt[c[p]] ++;
		if ( c[0] == c[1] ) k[idx].r ++ , k[idx].c ++;
		else {
			idx ++;
			k[idx].be = c[p];
			k[idx].l = k[idx].r = i , k[idx].c = 1;
		}
	} 
	int la1 , la2;
	la1 = k[0].be ^ 1 , la2 = 0;
	while ( cnt[0] > 0 && cnt[1] > 0 ){
		for ( ; la2 <= idx ; la2 ++ )
			if ( k[la2].be ^ la1 ) break;
		if ( la2 > idx ){
			la2 = 0;
			printf ( "\n" );
			continue;
		} 
		if ( k[la2].c ) printf ( "%d " , k[la2].r - k[la2].c + 1 ) , t[k[la2].r - k[la2].c + 1] = 0 , k[la2].c -- , cnt[la1] -- , la1 ^= 1;
		else la2 ++;
	}
	la1 = max( cnt[0] , cnt[1] );
	while( la1 > 0 ){
		for ( ; la2 <= idx ; la2 ++ )
			if ( k[la2].c ) break;
		if ( la2 > idx ){
			la2 = 0;
			printf ( "\n" );
			continue;
		} 
		printf ( "%d " , k[la2].r - k[la2].c + 1 ) , t[k[la2].r - k[la2].c + 1] = 0 , la1 -- , k[la2].c --;
	}
	return 0;
}
